package com.xml;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.htmlparser.Node;
import org.htmlparser.Parser;
import org.htmlparser.Remark;
import org.htmlparser.Tag;
import org.htmlparser.filters.AndFilter;
import org.htmlparser.filters.NodeClassFilter;
import org.htmlparser.filters.NotFilter;
import org.htmlparser.filters.TagNameFilter;
import org.htmlparser.nodes.RemarkNode;
import org.htmlparser.nodes.TagNode;
import org.htmlparser.nodes.TextNode;
import org.htmlparser.tags.ScriptTag;
import org.htmlparser.tags.TableColumn;
import org.htmlparser.tags.TableRow;
import org.htmlparser.tags.TableTag;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.SimpleNodeIterator;
import org.mk.type.IntegerType;
import org.mk.type.MySQLTypeFactory;

import com.db.ColumnInfoBean;
import com.db.ForeignKey;
import com.excel.read.Config;
import com.excel.read.DBTable;
import com.operation.OperationMap;
import com.operation.RecordOperation;


public class GetRecordExtract extends AbstractRecordExtract{


	// 循环访问所有节点，输出包含关键字的值节点
	public OperationMap extractOperationMap(String html, long storeFrom)
			throws Exception {
		Parser parser = new Parser();
		parser.setInputHTML(html);
		parser.setEncoding("gb2312");
		// 迭代所有节点, null 表示不使用 NodeFilter
		TagNameFilter tf = new TagNameFilter("TABLE");
		NotFilter ntFilter = new NotFilter(new NodeClassFilter(ScriptTag.class));
		AndFilter rorFilter = new AndFilter(tf, ntFilter);
		NodeList list = parser.parse(tf);
		
		 //确定是内容节点的时候做
		 MyNotFilter myNotFilter = new MyNotFilter();
		 //div
		 myNotFilter.accept(list.elementAt(0));		
		
		 //取得Map的条数
		 TableTag tn = (TableTag)list.elementAt(0);
		 
			 OperationMap opMap = new OperationMap(storeFrom);
			 List<String> tableNames = new ArrayList<String>();
			 Map tableMap = new HashMap();
				 List<Record>  aList = getRecordList(tn);
				 String tableName = aList.get(0).getTableName();
				 String operation = aList.get(0).op;
				 if(operation != null && operation.equalsIgnoreCase("get")) {
					 opMap.opTableName = tableName;
					 opMap.record = aList.get(0);
				 }
				 tableMap.put(tableName, aList);
				 tableNames.add(tableName);		
				 opMap.aMap = tableMap;
				 opMap.tableNames = tableNames;
		return opMap;

	}
	
	

	
}
